﻿Imports System.Data.OleDb

Public Class createProfile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub


    Protected Sub btn_saveProfile_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_saveProfile.Click
        Dim newFileName As String = ""

        'Check to see if the picture file has been added for upload
        If fu_profilePicture2.HasFile Then

            'Stop it creating a load of zeroes a generate an actual GUID
            Dim myGUID = Guid.NewGuid
            'Turn this GUID into a string and add the jpeg file extension to make a unique file name (but what if it was a .gif or .tiff etc?)
            newFileName = myGUID.ToString() + ".jpg"

            'Find the pictures folder and save the image there using its randomnly generated filename
            Dim picLocationOnServerHardDisk = Request.MapPath("img") & "/" & newFileName
            fu_profilePicture2.SaveAs(picLocationOnServerHardDisk)

        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("diycakeConnectionString").ConnectionString)
        Dim SqlString As String = "INSERT INTO cakers (userFName,userLName,userDesc,userImg,userDob,userLoc,userUrl,userStar,userAge,userDateAdded) VALUES (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f9,@f10,@f11) WHERE userUName = @f8"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_userFName2.Text)
        cmd.Parameters.AddWithValue("@f2", tb_userLName2.Text)
        cmd.Parameters.AddWithValue("@f3", tb_userDesc2.Text)
        cmd.Parameters.AddWithValue("@f4", "img/" & newFileName)
        cmd.Parameters.AddWithValue("@f5", tb_userDOB2.Text)
        cmd.Parameters.AddWithValue("@f6", tb_userLoc2.Text)
        cmd.Parameters.AddWithValue("@f7", tb_userUrl2.Text)
        cmd.Parameters.AddWithValue("@f8", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f9", "0")
        cmd.Parameters.AddWithValue("@f10", tb_userAge2.Text)
        cmd.Parameters.AddWithValue("@f11", DateTime.Now.ToString())
        oleDbConn.Open()
        cmd.ExecuteNonQuery()


        'Redirect the user to their own profile page
        Response.Redirect("profile.aspx?userUName=" & User.Identity.Name)
    End Sub
End Class